package com.tengju.support.infrastructure.persistence.redis;

import com.tengju.support.domain.model.wx.WechatGradeRepository;
import com.tengju.support.infrastructure.persistence.redis.dataobject.RedisKeyObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;

import static com.tengju.support.infrastructure.persistence.redis.dataobject.RedisKeyPrefix.DEALER_GRADE_WX;

@Repository
public class WechatGradeRepositoryImpl implements WechatGradeRepository {
    private final RedisService redisService;

    public WechatGradeRepositoryImpl(RedisService redisService) {
        this.redisService = redisService;
    }

    @Override
    public boolean businessIdExist(String businessId) {
        RedisKeyObject key = new RedisKeyObject(DEALER_GRADE_WX, businessId);
        String value = redisService.getString(key);
        if (StringUtils.isNotBlank(value)) {
            return true;
        }
        return false;
    }

    @Override
    public void setBusinessId(String businessId) {
        RedisKeyObject key = new RedisKeyObject(DEALER_GRADE_WX, businessId);
        redisService.setValue(key, businessId, 1, TimeUnit.DAYS);
    }
}
